<?php include __DIR__ . "/../../php/db.php"; ?>
<!DOCTYPE html>
<head>
	<title>Personal Information</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet" type="text/css">
	<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
	<link href="css/bootstrap.min.resume.css" rel="stylesheet" type="text/css">
	<link href="css/resumestyle.css" rel="stylesheet" type="text/css">	
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
	<script src="../../js/bootstrap.min.js"></script>
    <script src="../../js/docs.min.js"></script>
    <script src="../../js/ie10-viewport-bug-workaround.js"></script>
	<script src="../../js/modernizr.js"></script> <!-- Modernizr -->

<?php
 
$login = $_SESSION['login'];

$userid = mysql_query("SELECT * FROM `flss`.`accounts` WHERE `user` = '$login'");
while($rowshow = mysql_fetch_array($userid))
{
	$getid = $rowshow['account_id'];
}
$getallcountry = mysql_query("SELECT * FROM `flss`.`country`");
while($rowcountry = mysql_fetch_array($getallcountry))
{
    $countries[] = array("id" => $rowcountry['country_no'], "val" => $rowcountry['country']);
	
}

$getallnationality = mysql_query("SELECT * FROM `flss`.`nationality`");
$nationalities = array();
while($rowx = mysql_fetch_array($getallnationality))
{
	
    $nationalities[] = array(
							"id" => $rowx['nationality_no'], 
							"val" => $rowx['nationality']
							);
	
}

$applicant_id = $_SESSION['applicant_id'];
$query = "SELECT * FROM applicant a 
          LEFT JOIN a_address aa ON aa.applicant_id = a.applicant_id
          WHERE a.applicant_id = {$applicant_id}";
$myinfo = mysql_fetch_array(mysql_query($query));
//var_dump($myinfo); echo mysql_error(); die;
$jsonCountry = json_encode($countries);
$jsonNationalities = json_encode($nationalities);

?>
<script type="text/javascript">
	 <?php
       echo "var countries = $jsonCountry; \n";
   //    echo "var nationalities = $jsonNationalities; \n";
      
	  ?>
	  function loadall()
	 	{
			loadCountry();
			//loadNationalities();
			}
	   function loadCountry(){
	  	var select = document.getElementById("countries");
        for(var i = 0; i < countries.length; i++){
          select.options[i] = new Option(countries[i].val,countries[i].id);          
          if(select.options[i].text == "<?=$myinfo['country']?>"){
          	select.options[i].selected = true;
          }
        }
	  	
	  }
	  
	   function loadNationalities(){
	  	var select = document.getElementById("nationality");
        for(var i = 0; i < nationalities.length; i++){
          select.options[i] = new Option(nationalities[i].val,nationalities[i].id);          
        }
	  }


</script>
</head>
<body onLoad="loadall()" class="templatemo-bg-gray" >
	<div class="container" style="overflow-x:hidden;">
		<div class="col-md-12">	
			<h1 class="text-center margin-bottom-15">Personal Information</h1>		
			<form id ="frm1" method="post" class="form-horizontal templatemo-contact-form-2 templatemo-container" >
				<div class="row">
					<div class="col-md-6" style="width: 290px;">
						<div class="form-group">				          		          	
				           	<div class="col-sm-12" style="padding-left: 0px;">
				            	<div class="templatemo-input-icon-container">
				            		<input type="text" class="form-control" id="txtFname" placeholder="First Name" style="width: 280px;" value="<?=$myinfo['fname']?>" required>
				            	</div>		            		            		            
				          	</div>              
				        </div>
				      </div>
				  <div class="row">
					<div class="col-md-6" style="width: 130px;">
				        <div class="form-group">
				            <div class="col-sm-12" style="padding-left:0px;">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?=$myinfo['mname']?>" type="text" class="form-control" id="txtMname" placeholder="Middle Name" style="width: 280px;" required>
				            	</div>
				          	</div>
				        </div>
				    </div>
				  <div class="row">
					<div class="col-md-6" style="width: 130px;">
				        <div class="form-group">
				            <div class="col-sm-12" style="padding-left:0px;">
				            	<div class="templatemo-input-icon-container" style="padding-left: 160px;">
				            		<input value="<?=$myinfo['lname']?>" type="text" class="form-control" id="txtLname" placeholder="Last Name" style="width: 280px;" required>
				            	</div>
				          	</div>
				        </div>
				    </div>
				  </div>
			        </div>
				<div class="row">
				 <div class="col-md-6">
						<div class="form-group">
				          <div class="col-md-12">
				            <div class="templatemo-input-icon-container">
				            	<textarea  id="txtHomeAddress" class="form-control"  placeholder="Home Address" style="width: 350px; height: 34px;" required><?=$myinfo['a_address']?></textarea>
				            </div>
				          </div>
				        </div>
				     </div>
					<div class="col-md-6" style="width: 60px;">
				        <div class="form-group">
				            <div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?=$myinfo['city']?>" id="txtCity" type="text" class="form-control"  placeholder="City" style="width: 250px; margin-left:-100px;" required>
				            	</div>
				          	</div>
				        </div>
				    </div>
				  <div class="row">
					<div class="col-md-6" style="left: 200px;width: 180px; height:35px;">
						<div class="col-md-12 form-group">				         				         
					         <div class="templatemo-inline-group">
					         	<div class="col-sm-12 templatemo-select-container">
					         		<select name="country" id="countries" style="height: 32px; margin-left:-100px" required>

								</select>
					         </div>
						</div>
				    </div>
				  </div>
				</div>
			</div>
				<div class="row">
					<div class="col-md-6">
						<div class="form-group">				          		          	
				           	<div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?=$myinfo['tel']?>" type="text" class="form-control" id="txtTelephone" placeholder="Telephone" style="width: 350px;">
				            	</div>		            		            		            
				          	</div>              
				        </div>
				      </div>
				  <div class="row">
					<div class="col-md-6">
				        <div class="form-group">
				            <div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input  value="<?=$myinfo['mobile']?>" type="text" class="form-control" id="txtMobile" placeholder="Mobile" style="width: 350px; margin-left:-100px;" required>
				            	</div>
				          	</div>
				        </div>
				    </div>
				  </div>
				</div>
				<div class="row">
					<div class="col-md-6">
						<div class="col-md-12 form-group">			         				         
					         <div class="templatemo-inline-group">
					         	<div class="col-sm-12 templatemo-select-container">
					         		<label class="control-label">Date of Birth</label> &nbsp; &nbsp; &nbsp;	&nbsp;  
									<select name="month" id="selMonth" style="height: 32px;width: 102px;" required>
									  <option selected="" disabled="">Month</option>
									   <option value="01">January</option>
									   <option value="02">February</option>
									   <option value="03">March</option>
									   <option value="04">April</option>
									   <option value="05">May</option>
									   <option value="06">June</option>
									   <option value="07">July</option>
									   <option value="08">August</option>
									   <option value="09">September</option>
									   <option value="10">October</option>
									   <option value="11">November</option>
									   <option value="12">December</option>
									  </select>
									  <select name="selDay" id="selDay" style="height: 32px;width: 57px;" required>
									  <option selected="" disabled="">Day</option>
									   <option value="1">1</option>
									   <option value="2">2</option>
									   <option value="3">3</option>
									   <option value="4">4</option>
									   <option value="5">5</option>
									   <option value="6">6</option>
									   <option value="7">7</option>
									   <option value="8">8</option>
									   <option value="9">9</option>
									   <option value="10">10</option>
									   <option value="11">11</option>
									   <option value="12">12</option>
									   <option value="13">13</option>
									   <option value="14">14</option>
									   <option value="15">15</option>
									   <option value="16">16</option>
									   <option value="17">17</option>
									   <option value="18">18</option>
									   <option value="19">19</option>
									   <option value="20">20</option>
									   <option value="21">21</option>
									   <option value="22">22</option>
									   <option value="23">23</option>
									   <option value="24">24</option>
									   <option value="25">25</option>
									   <option value="26">26</option>
									   <option value="27">27</option>
									   <option value="28">28</option>
									   <option value="29">29</option>
									   <option value="30">30</option>
									   <option value="31">31</option>
									  </select>
									  <input type="text" name="year" id="txtYear" style="height: 32px;width: 67px;" placeholder="Year" required>
										
					         	</div>
							</div>
				    </div>
				      </div>
				  <div class="row" style="width: 1200px;">
					<div class="col-md-6" style="width: 31px;">
				        <div class="form-group">
				            <div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?=$myinfo['pob']?>" type="text" class="form-control" id="txtPob" placeholder="Place of Birth" style="width: 350px; margin-left:-100px;">
				            	</div>
				          	</div>
				        </div>
				    </div>
					<div class="col-md-6 templatemo-radio-group" style="padding-left: 250px;">
			          	<label class="radio-inline">
		          			<input <?php if($myinfo['gender'] == "Male"){echo "checked";} ?> id="optMale" type="radio" name="optionsRadios" value="Male"> Male
		          		    </label>
		          		    <label class="radio-inline">
		          			<input <?php if($myinfo['gender'] == "Female"){echo "checked";} ?> id= "optFemale" type="radio" name="optionsRadios"  value="Female"> Female
		          		</label>
			          </div> 
				</div>
			</div>
				   <div class="row">
					<div class="col-md-6" style="width: 365px;">
						<div class="col-md-12 form-group">				         				         
					         <div class="templatemo-inline-group">
					         	<div class="col-sm-12 templatemo-select-container">
								  <select name="civilstatus" id="selCivil" style="width: 352px; height: 32px; padding-left:20px;" required>
								  <option selected="" disabled="">Civil Status</option>
								  <option value="single">Single</option>
								  <option value="married">Married</option>
								  <option value="widowed">Widowed</option>
								  <option value="separated">Separated</option>
								  <option value="divorced">Divorced</option>
								  </select>
					         	</div>
							</div>
				    	</div>
				      </div>
					<div class="col-md-6" style="padding-left: 15px;">
						<div class="col-md-12 form-group" style="padding-left:30px;">				         				         
					         <div class="templatemo-inline-group">
					         	<div class="col-sm-12 templatemo-select-container">
								
                                <select name="nation" id="nationality" style="width: 352px; height: 32px; padding-left:20px" required>
									  <?php foreach($nationalities as $value){ ?>
										  <option <?php if($myinfo['nationality'] == $value['val']){echo "selected";} ?> value="<?=$value['val']?>"><?=$value['val']?></option>
									  <?php }?>    
								    </select>
					         	</div>
							</div>
				    	</div>
				    </div>
				</div>
				<div class="row">
					<div class="col-md-6">
						<div class="form-group">				          		          	
				           	<div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?php if($myinfo['height']){echo $myinfo['height'];}?>" type="text" class="form-control" id="txtHeight" placeholder="Height in cm" style="width: 350px;" required>
				            	</div>		            		            		            
				          	</div>              
				        </div>
				      </div>
				  <div class="row">
					<div class="col-md-6">
				        <div class="form-group">
				            <div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?php if($myinfo['weight']){echo $myinfo['weight'];}?>" type="text" class="form-control" id="txtWeight" placeholder="Weight in kl" style="width: 350px; margin-left:-100px;" required>
				            	</div>
				          	</div>
				        </div>
				    </div>
				  </div>
				</div>
				<div class="row">
					<div class="col-md-6">
						<div class="form-group">				          		          	
				           	<div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?=$myinfo['religion']?>" type="text" class="form-control" id="txtReligion" placeholder="Religion" style="width: 443px;" required>
				            	</div>		            		            		            
				          	</div>              
				        </div>
				      </div>
				  <div class="row">
					<div class="col-md-6">
				        <div class="form-group">
				            <div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?php if($myinfo['children']){echo $myinfo['children'];}?>" type="text" class="form-control" id="txtChildren" placeholder="No. of Children" style="width: 150px; margin-left:-10px;">
				            	</div>
				          	</div>
				        </div>
				    </div>
				  </div>
				</div>
				<div class="row">
					<div class="col-md-6">
						<div class="form-group">				          		          	
				           	<div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?=$myinfo['father']?>" type="text" class="form-control" id="txtFather" placeholder="Father's Name" style="width: 643px;">
				            	</div>		            		            		            
				          	</div>              
				        </div>
				      </div>
				     </div>
				     <div class="row">
				     	<div class="col-md-6">
						<div class="form-group">				          		          	
				           	<div class="col-sm-12">
				            	<div class="templatemo-input-icon-container">
				            		<input value="<?=$myinfo['mother']?>" type="text" class="form-control" id="txtMother" placeholder="Mother's Name" style="width: 643px;">
				            	</div>		            		            		            
				          	</div>              
				        </div>
				      </div>
				     </div>
		        <div class="form-group">
		          <div class="col-md-12">
		            <input id="btnSaveResume" type="button" value="SAVE" class="btn btn-warning pull-right">		            
		          </div>
		        </div>		    	
		      </form>	 
		</div>
	</div>
<script type="text/javascript">
	$(function(){
		function saveResume($applicant_id,$fname,$mname,$lname,$gender,$a_address,$city,$country,$telephone,$mobile,$bdate,$pob,$civilstatus,$nationality,$height,$weight,$religion,$noofchildren,$fathersname,$mothersname){
			var params = {};
			params.applicant_id = $applicant_id;
			params.fname = $fname;
			params.mname = $mname;
			params.lname = $lname;
			params.gender = $gender;
			params.a_address = $a_address;
			params.city = $city;
			params.country = $country;
			params.telephone = $telephone;
			params.mobile = $mobile;
			params.mybdate = $bdate;
			params.pob = $pob;
			params.civilstatus = $civilstatus;
			params.nationality = $nationality;
			params.height = $height;
			params.weight = $weight;
			params.religion = $religion;
			params.noofchildren = $noofchildren;
			params.fathersname = $fathersname;
			params.mothersname = $mothersname;
			return	$.ajax({
						url: '<?=BASE_URL?>' + 'api/save.php',
						data: params,
						type: 'post',
						dataType: 'json'
					});
		}
		$(document).ready(function(){
			$('#btnSaveResume').click(function(){

				var female = document.getElementById('optFemale').checked;	
				var male = document.getElementById('optMale').checked;
				var month = $('#selMonth option:selected').val();
				var day = $('#selDay option:selected').val();
				var year = $('#txtYear').val();
				var bdate = '';
				if(month && day && year){
					bdate = year + '-' + month + ',' + day;
				}


				var gender;
				if(!male && !female){
					gender = "bading"
				}else if(male){
					gender ="Male";
				}else{
					gender ="Female";
				}
				var $applicant_id = "<?=$_SESSION['applicant_id']?>";
				var $fname = $('#txtFname').val();
				var $mname = $('#txtMname').val();
				var $lname = $('#txtLname').val();
				var $gender = gender;
				var $a_address= $('#txtHomeAddress').val();
				var $city = $('#txtCity').val();
				var $country = $('#countries option:selected').text();
				var $telephone = $('#txtTelephone').val();
				var $mobile = $('#txtMobile').val();
				var $bdate = bdate;
				var $pob = $('#txtPob').val();
				var $civilstatus = $('#selCivil option:selected').val();
				var $nationality = $('#nationality option:selected').val();
				var $height = $('#txtHeight').val();
				var $weight = $('#txtWeight').val();
				var $religion = $('#txtReligion').val();
				var $noofchildren = $('#txtChildren').val();
				var $fathersname = $('#txtFather').val();
				var $mothersname = $('#txtMother').val();
		
					saveResume($applicant_id,$fname,$mname,$lname,$gender,$a_address,$city,$country,$telephone,$mobile,$bdate,$pob,$civilstatus,$nationality,$height,$weight,$religion,$noofchildren,$fathersname,$mothersname).done(function(result){
						if(result.status){
							window.location.reload();
						}
					});
				
			});
		});	
	});

</script>
</body>
</html>